﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;
using BrokerBase.Lib.Product;

namespace broker.duty.YG
{
    class Class18
    {


        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("重大疾病"))
            {

                IPolicy bp = ppa.SchemePeriodActing.BasicPolicyPeriodActing.PolicyActing.Policy;
                IEnumerable<IDuty> ds =bp.Product.Duties.Where(p => p.Name.Contains("账户"));

                double acount = 0f;

                foreach (IDuty d in ds)
                {
                    acount += ppa.SchemePeriodActing.BasicPolicyPeriodActing.GetDutyTotalValue(d.Name);
                }

                double s = acount * 1.05;

                da.Value = s > ppa.Amount ? s : ppa.Amount;
                ppa.IsCurrentFinish = true;
                da.Description = "个人账户与保额取较大者";

                double x = da.Value / bp.Amount;

                double bpamt = ppa.SchemePeriodActing.BasicPolicyPeriodActing.Amount;

                ppa.SchemePeriodActing.BasicPolicyPeriodActing.Amount = bpamt - (bpamt * x) > 0 ? bpamt - (bpamt * x) : 0;

                if (ppa.SchemePeriodActing.BasicPolicyPeriodActing.Amount <= double.Epsilon)
                {
                    ppa.IsCurrentFinish = true;
                }

                
            }
        }
    }
}
